import { refreshData, refreshDataApi } from '../../../../api/ljsz'

export default {
  data() {
    return {
      textarea: ''
    }
  },
  created() {
    this.refresh4G()
  },
  mounted() {

  },
  methods: {
    /**
     * 刷新4g接收数据的内容
     */
    refresh4G() {
      // var ws = new WebSocket("http://127.0.0.1:8090/4g-data")
      // let ws = new WebSocket("http://127.0.0.1:8090")
      let ws = new WebSocket('ws://127.0.0.1:8091')
      ws.onopen = function() {
        console.log("WebSocket connection established.")
      };
      ws.onmessage = function(event) {
        console.log("Message received: " + event.data)
        this.textarea = event.data
      };
      ws.onclose = function() {
        console.log("WebSocket connection closed.")
      }
      // 发送消息
      // ws.send("123")
      refreshDataApi().then(res => {
        if (res.code === 0) {
          this.textarea = res.data
        } else {
          this.$message.error('4g数据接收失败!')
        }
      })
    }
  }
}
